package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import to.Usuario;
import factory.ConnectionFactory;

public class UsuarioDAO {

	public List<Usuario> buscaUsuario(String user, String pas){

		List<Usuario> usuarios = new ArrayList<Usuario>();
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try{
			
			conn = ConnectionFactory.getConnection();
			
			String sql = "SELECT * FROM tb_usuarios where login = '"+user+"'";
			
			stmt = conn.prepareStatement(sql);
			
			rs = stmt.executeQuery();
			
			while(rs.next()){
				
				Usuario u = new Usuario();
				u.setNome(rs.getString("nome"));
				
				usuarios.add(u);
			}
			
			conn.close();
			
		}catch(Exception e){
			System.out.println("Erro: "+e);
		}finally{
			try { if(conn != null) conn.close(); } catch (SQLException e) {}
			try { if(stmt != null) stmt.close(); } catch (SQLException e) {}
			try { if(rs != null) rs.close(); } catch (SQLException e) {}
		}
		
		
		return usuarios;
	
	}
}
